package com.hannesdorfmann.mosby3.mvi.integrationtest.slice;

import com.hannesdorfmann.mosby3.mvi.MviAbilitySlice;
import com.hannesdorfmann.mosby3.mvi.integrationtest.ResourceTable;
import com.hannesdorfmann.mosby3.mvi.integrationtest.eager.EagerPresenter;
import com.hannesdorfmann.mosby3.mvi.integrationtest.eager.EagerView;
import io.reactivex.Observable;
import io.reactivex.subjects.ReplaySubject;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Text;


public class EagerViewAbilitySlice extends MviAbilitySlice<EagerView, EagerPresenter> implements EagerView {

    public ReplaySubject<String> renderedStrings =  ReplaySubject.create();

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_eager_view);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public Observable<String> intent1() {
        return Observable.just("Intent 1").startWith("Before Intent 1");
    }

    @Override
    public Observable<String> intent2() {
        return Observable.just("Intent 2");
    }

    @Override
    public void render(String state) {
        ((Text) findComponentById(ResourceTable.Id_text)).setText(state);
        renderedStrings.onNext(state);
    }

    @Override
    public EagerPresenter createPresenter() {
        return new EagerPresenter();
    }
}
